//package com.chenl.provider.DEMOS.重复点击处理;
//
//
//import com.alibaba.fastjson.JSONObject;
//import com.google.common.cache.Cache;
//import com.google.common.cache.CacheBuilder;
//import lombok.extern.slf4j.Slf4j;
//import org.aspectj.lang.JoinPoint;
//import org.aspectj.lang.annotation.Aspect;
//import org.aspectj.lang.annotation.Before;
//import org.aspectj.lang.reflect.MethodSignature;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.expression.spel.standard.SpelExpressionParser;
//import org.springframework.expression.spel.support.StandardEvaluationContext;
//import org.springframework.util.StringUtils;
//
//import java.lang.reflect.Method;
//import java.lang.reflect.Parameter;
//import java.util.concurrent.TimeUnit;
//
//@Aspect
//@Configuration
//@Slf4j
//public class LockMethodInterceptor {
//    //定义缓存，设置最大缓存数及过期日期
//    private static final Cache<String,Object> CACHE = CacheBuilder.newBuilder().maximumSize(1000).expireAfterWrite(2, TimeUnit.SECONDS).build();
//
//    @Before("@annotation(com.chenl.provider.DEMOS.重复点击处理.LocalLock)")
//    public void interceptor(JoinPoint joinPoint){
//        MethodSignature signature = (MethodSignature) joinPoint.getSignature();
//        Method method = signature.getMethod();
//        LocalLock localLock = method.getAnnotation(LocalLock.class);
//        String key = getKey(localLock.key(),method, joinPoint.getArgs());
//        System.out.println("key:"+key);
//        String keyWrapper = "LocalLock:"+ localLock.message() + ":" + key;
//        if(!StringUtils.isEmpty(keyWrapper)){
//            if(CACHE.getIfPresent(keyWrapper) != null){
//                log.error("请勿重复请求key:{}",keyWrapper);
//                log.error("请勿重复请求joinPoint.getArgs():{}",joinPoint.getArgs());
//                throw new RuntimeException("请勿重复点击！");
//
//            }
//            CACHE.put(keyWrapper,keyWrapper);
//        }
//    }
//
//    private String getKey(String keyExpress, Method method, Object[] args){
////        for (int i = 0; i < args.length; i++) {
////            keyExpress = keyExpress.replace("arg[" + i + "]", args[i].toString());
////        }
////        return keyExpress;
//        SpelExpressionParser parser = new SpelExpressionParser();
//        StandardEvaluationContext context = new StandardEvaluationContext();
//        Parameter[] parameters = method.getParameters();
//        for(int i = 0; i < parameters.length; i++){
//            context.setVariable(parameters[i].getName(), args[i]);
//        }
//        return JSONObject.toJSONString(parser.parseExpression(keyExpress).getValue(context));
//    }
//}